package com.xjpos.sas.security;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class Md5PasswordEncoderAdapter implements PasswordEncoder {

    private Md5PasswordEncoder passwordEncoder;

    public Md5PasswordEncoderAdapter(Md5PasswordEncoder encoder) {
        this.passwordEncoder = encoder;
    }

    @Override
    public String encode(CharSequence rawPassword) {
        return passwordEncoder.encodePassword(rawPassword.toString(), null);
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return passwordEncoder.isPasswordValid(encodedPassword, rawPassword.toString(), null);
    }
}
